Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handling for redirects from getStaticProps/getServerSideProps #16642

Merged
merged 14 commits into from
Sep 8, 2020

Conversation

ijjk
Copy link
Member

@ijjk ijjk commented Aug 28, 2020

This implements the RFC posted here #14890

Closes: #16587

@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@ijjk
Copy link
Member Author

ijjk commented Aug 28, 2020

Stats from current PR

Default Server Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
buildDuration 12.8s 12.5s -316ms
nodeModulesSize 57.5 MB 57.5 MB ⚠️ +7.84 kB
Page Load Tests Overall increase ✓
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
/ failed reqs 0 0
/ total time (seconds) 2.469 2.395 -0.07
/ avg req/sec 1012.39 1043.91 +31.52
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.415 1.413 0
/error-in-render avg req/sec 1767.11 1769.36 +2.25
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..f20b.js gzip 10.3 kB 10.4 kB ⚠️ +124 B
framework.HASH.js gzip 39 kB 39 kB
main-ce79c9a..12c9.js gzip 7.36 kB 7.36 kB
webpack-e067..f178.js gzip 751 B 751 B
Overall change 57.3 kB 57.5 kB ⚠️ +124 B
Client Bundles (main, webpack, commons) Modern Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..dule.js gzip 6.13 kB 6.23 kB ⚠️ +103 B
framework.HA..dule.js gzip 39 kB 39 kB
main-9973c26..dule.js gzip 6.42 kB 6.42 kB
webpack-07c5..dule.js gzip 751 B 751 B
Overall change 52.3 kB 52.4 kB ⚠️ +103 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
polyfills-4b..e242.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-9a0b9e1..b37e.js gzip 1.28 kB 1.28 kB
_error-28298..e0c9.js gzip 3.44 kB 3.44 kB
hooks-89731c..c609.js gzip 887 B 887 B
index-17468f..5d83.js gzip 227 B 227 B
link-000f151..65d4.js gzip 1.29 kB 1.29 kB
routerDirect..924c.js gzip 284 B 284 B
withRouter-7..c13d.js gzip 284 B 284 B
Overall change 7.69 kB 7.69 kB
Client Pages Modern
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-75d3a82..dule.js gzip 625 B 625 B
_error-65c8a..dule.js gzip 2.29 kB 2.29 kB
hooks-cbf13f..dule.js gzip 387 B 387 B
index-b9a643..dule.js gzip 226 B 226 B
link-4cfda7a..dule.js gzip 1.26 kB 1.26 kB
routerDirect..dule.js gzip 284 B 284 B
withRouter-f..dule.js gzip 282 B 282 B
Overall change 5.35 kB 5.35 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_buildManifest.js gzip 322 B 322 B
_buildManife..dule.js gzip 330 B 330 B
Overall change 652 B 652 B
Rendered Page Sizes Overall decrease ✓
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
index.html gzip 972 B 971 B -1 B
link.html gzip 978 B 977 B -1 B
withRouter.html gzip 964 B 963 B -1 B
Overall change 2.91 kB 2.91 kB -3 B

Diffs

Diff for 677f882d2ed8..60.module.js
@@ -1041,7 +1041,39 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
               as,
               shallow
             );
-            var { error } = routeInfo;
+            var { error, props, __N_SSG, __N_SSP } = routeInfo; // handle redirect on client-transition
+
+            if (
+              (__N_SSG || __N_SSP) &&
+              props &&
+              props.pageProps &&
+              props.pageProps.__N_REDIRECT
+            ) {
+              var destination = props.pageProps.__N_REDIRECT; // check if destination is internal (resolves to a page) and attempt
+              // client-navigation if it is falling back to hard navigation if
+              // it's not
+
+              if (destination.startsWith("/")) {
+                var parsedHref = (0, _parseRelativeUrl.parseRelativeUrl)(
+                  destination
+                );
+
+                this._resolveHref(parsedHref, pages);
+
+                if (pages.includes(parsedHref.pathname)) {
+                  return this.change(
+                    "replaceState",
+                    destination,
+                    destination,
+                    options
+                  );
+                }
+              }
+
+              window.location.href = destination;
+              return new Promise(() => {});
+            }
+
             Router.events.emit("beforeHistoryChange", as);
             this.changeState(method, url, as, options);
Diff for 677f882d2ed8..886051899.js
@@ -1117,6 +1117,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                     missingParams,
                     routeInfo,
                     error,
+                    props,
+                    __N_SSG,
+                    __N_SSP,
+                    destination,
+                    parsedHref,
                     appComp;
 
                   return _regeneratorRuntime.wrap(
@@ -1297,14 +1302,67 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
 
                           case 51:
                             routeInfo = _context.sent;
-                            error = routeInfo.error;
+                            (error = routeInfo.error),
+                              (props = routeInfo.props),
+                              (__N_SSG = routeInfo.__N_SSG),
+                              (__N_SSP = routeInfo.__N_SSP); // handle redirect on client-transition
+
+                            if (
+                              !(
+                                (__N_SSG || __N_SSP) &&
+                                props &&
+                                props.pageProps &&
+                                props.pageProps.__N_REDIRECT
+                              )
+                            ) {
+                              _context.next = 62;
+                              break;
+                            }
+
+                            destination = props.pageProps.__N_REDIRECT; // check if destination is internal (resolves to a page) and attempt
+                            // client-navigation if it is falling back to hard navigation if
+                            // it's not
+
+                            if (!destination.startsWith("/")) {
+                              _context.next = 60;
+                              break;
+                            }
+
+                            parsedHref = (0,
+                            _parseRelativeUrl.parseRelativeUrl)(destination);
+
+                            this._resolveHref(parsedHref, pages);
+
+                            if (!pages.includes(parsedHref.pathname)) {
+                              _context.next = 60;
+                              break;
+                            }
+
+                            return _context.abrupt(
+                              "return",
+                              this.change(
+                                "replaceState",
+                                destination,
+                                destination,
+                                options
+                              )
+                            );
+
+                          case 60:
+                            window.location.href = destination;
+                            return _context.abrupt(
+                              "return",
+                              new Promise(function() {})
+                            );
+
+                          case 62:
                             Router.events.emit("beforeHistoryChange", as);
                             this.changeState(method, url, as, options);
 
                             if (false) {
                             }
 
-                            _context.next = 58;
+                            _context.next = 67;
                             return this.set(
                               route,
                               pathname,
@@ -1316,9 +1374,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               else throw e;
                             });
 
-                          case 58:
+                          case 67:
                             if (!error) {
-                              _context.next = 61;
+                              _context.next = 70;
                               break;
                             }
 
@@ -1329,28 +1387,28 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
                             throw error;
 
-                          case 61:
+                          case 70:
                             if (false) {
                             }
 
                             Router.events.emit("routeChangeComplete", as);
                             return _context.abrupt("return", true);
 
-                          case 66:
-                            _context.prev = 66;
+                          case 75:
+                            _context.prev = 75;
                             _context.t0 = _context["catch"](48);
 
                             if (!_context.t0.cancelled) {
-                              _context.next = 70;
+                              _context.next = 79;
                               break;
                             }
 
                             return _context.abrupt("return", false);
 
-                          case 70:
+                          case 79:
                             throw _context.t0;
 
-                          case 71:
+                          case 80:
                           case "end":
                             return _context.stop();
                         }
@@ -1358,7 +1416,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                     },
                     _callee,
                     this,
-                    [[48, 66]]
+                    [[48, 75]]
                   );
                 })
               );
Diff for index.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -118,13 +118,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.b1af6078fa6886051899.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8bbd9ad3a3297b42720e.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
Diff for link.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -123,13 +123,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.b1af6078fa6886051899.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8bbd9ad3a3297b42720e.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
Diff for withRouter.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -118,13 +118,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.b1af6078fa6886051899.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8bbd9ad3a3297b42720e.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       async=""
       crossorigin="anonymous"
       type="module"

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
buildDuration 13.9s 14.1s ⚠️ +191ms
nodeModulesSize 57.5 MB 57.5 MB ⚠️ +7.84 kB
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..f20b.js gzip 10.3 kB N/A N/A
framework.HASH.js gzip 39 kB 39 kB
main-ce79c9a..12c9.js gzip 7.36 kB 7.36 kB
webpack-e067..f178.js gzip 751 B 751 B
677f882d2ed8..df1d.js gzip N/A 10.4 kB N/A
Overall change 57.3 kB 57.5 kB ⚠️ +124 B
Client Bundles (main, webpack, commons) Modern Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..dule.js gzip 6.13 kB N/A N/A
framework.HA..dule.js gzip 39 kB 39 kB
main-9973c26..dule.js gzip 6.42 kB 6.42 kB
webpack-07c5..dule.js gzip 751 B 751 B
677f882d2ed8..dule.js gzip N/A 6.23 kB N/A
Overall change 52.3 kB 52.4 kB ⚠️ +103 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
polyfills-4b..e242.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-9a0b9e1..b37e.js gzip 1.28 kB 1.28 kB
_error-28298..e0c9.js gzip 3.44 kB 3.44 kB
hooks-89731c..c609.js gzip 887 B 887 B
index-17468f..5d83.js gzip 227 B 227 B
link-000f151..65d4.js gzip 1.29 kB 1.29 kB
routerDirect..924c.js gzip 284 B 284 B
withRouter-7..c13d.js gzip 284 B 284 B
Overall change 7.69 kB 7.69 kB
Client Pages Modern
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-75d3a82..dule.js gzip 625 B 625 B
_error-65c8a..dule.js gzip 2.29 kB 2.29 kB
hooks-cbf13f..dule.js gzip 387 B 387 B
index-b9a643..dule.js gzip 226 B 226 B
link-4cfda7a..dule.js gzip 1.26 kB 1.26 kB
routerDirect..dule.js gzip 284 B 284 B
withRouter-f..dule.js gzip 282 B 282 B
Overall change 5.35 kB 5.35 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_buildManifest.js gzip 322 B 322 B
_buildManife..dule.js gzip 330 B 330 B
Overall change 652 B 652 B
Serverless bundles Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_error.js 1.03 MB 1.03 MB ⚠️ +1.47 kB
404.html 4.22 kB 4.22 kB
hooks.html 3.86 kB 3.86 kB
index.js 1.03 MB 1.03 MB ⚠️ +1.47 kB
link.js 1.07 MB 1.08 MB ⚠️ +2.3 kB
routerDirect.js 1.07 MB 1.07 MB ⚠️ +2.3 kB
withRouter.js 1.07 MB 1.07 MB ⚠️ +2.3 kB
Overall change 5.28 MB 5.29 MB ⚠️ +9.85 kB
Commit: f730244

@ijjk
Copy link
Member Author

ijjk commented Aug 28, 2020

Stats from current PR

Default Server Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
buildDuration 13.1s 13.8s ⚠️ +639ms
nodeModulesSize 57.5 MB 57.5 MB ⚠️ +8.44 kB
Page Load Tests Overall decrease ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
/ failed reqs 0 0
/ total time (seconds) 2.66 2.647 -0.01
/ avg req/sec 939.8 944.49 +4.69
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.665 1.691 ⚠️ +0.03
/error-in-render avg req/sec 1501.62 1478.75 ⚠️ -22.87
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..f20b.js gzip 10.3 kB 10.4 kB ⚠️ +124 B
framework.HASH.js gzip 39 kB 39 kB
main-ce79c9a..12c9.js gzip 7.36 kB 7.36 kB
webpack-e067..f178.js gzip 751 B 751 B
Overall change 57.3 kB 57.5 kB ⚠️ +124 B
Client Bundles (main, webpack, commons) Modern Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..dule.js gzip 6.13 kB 6.23 kB ⚠️ +103 B
framework.HA..dule.js gzip 39 kB 39 kB
main-9973c26..dule.js gzip 6.42 kB 6.42 kB
webpack-07c5..dule.js gzip 751 B 751 B
Overall change 52.3 kB 52.4 kB ⚠️ +103 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
polyfills-4b..e242.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-9a0b9e1..b37e.js gzip 1.28 kB 1.28 kB
_error-28298..e0c9.js gzip 3.44 kB 3.44 kB
hooks-89731c..c609.js gzip 887 B 887 B
index-17468f..5d83.js gzip 227 B 227 B
link-000f151..65d4.js gzip 1.29 kB 1.29 kB
routerDirect..924c.js gzip 284 B 284 B
withRouter-7..c13d.js gzip 284 B 284 B
Overall change 7.69 kB 7.69 kB
Client Pages Modern
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-75d3a82..dule.js gzip 625 B 625 B
_error-65c8a..dule.js gzip 2.29 kB 2.29 kB
hooks-cbf13f..dule.js gzip 387 B 387 B
index-b9a643..dule.js gzip 226 B 226 B
link-4cfda7a..dule.js gzip 1.26 kB 1.26 kB
routerDirect..dule.js gzip 284 B 284 B
withRouter-f..dule.js gzip 282 B 282 B
Overall change 5.35 kB 5.35 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_buildManifest.js gzip 322 B 322 B
_buildManife..dule.js gzip 330 B 330 B
Overall change 652 B 652 B
Rendered Page Sizes Overall decrease ✓
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
index.html gzip 972 B 971 B -1 B
link.html gzip 978 B 977 B -1 B
withRouter.html gzip 964 B 963 B -1 B
Overall change 2.91 kB 2.91 kB -3 B

Diffs

Diff for 677f882d2ed8..60.module.js
@@ -1041,7 +1041,39 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
               as,
               shallow
             );
-            var { error } = routeInfo;
+            var { error, props, __N_SSG, __N_SSP } = routeInfo; // handle redirect on client-transition
+
+            if (
+              (__N_SSG || __N_SSP) &&
+              props &&
+              props.pageProps &&
+              props.pageProps.__N_REDIRECT
+            ) {
+              var destination = props.pageProps.__N_REDIRECT; // check if destination is internal (resolves to a page) and attempt
+              // client-navigation if it is falling back to hard navigation if
+              // it's not
+
+              if (destination.startsWith("/")) {
+                var parsedHref = (0, _parseRelativeUrl.parseRelativeUrl)(
+                  destination
+                );
+
+                this._resolveHref(parsedHref, pages);
+
+                if (pages.includes(parsedHref.pathname)) {
+                  return this.change(
+                    "replaceState",
+                    destination,
+                    destination,
+                    options
+                  );
+                }
+              }
+
+              window.location.href = destination;
+              return new Promise(() => {});
+            }
+
             Router.events.emit("beforeHistoryChange", as);
             this.changeState(method, url, as, options);
Diff for 677f882d2ed8..886051899.js
@@ -1117,6 +1117,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                     missingParams,
                     routeInfo,
                     error,
+                    props,
+                    __N_SSG,
+                    __N_SSP,
+                    destination,
+                    parsedHref,
                     appComp;
 
                   return _regeneratorRuntime.wrap(
@@ -1297,14 +1302,67 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
 
                           case 51:
                             routeInfo = _context.sent;
-                            error = routeInfo.error;
+                            (error = routeInfo.error),
+                              (props = routeInfo.props),
+                              (__N_SSG = routeInfo.__N_SSG),
+                              (__N_SSP = routeInfo.__N_SSP); // handle redirect on client-transition
+
+                            if (
+                              !(
+                                (__N_SSG || __N_SSP) &&
+                                props &&
+                                props.pageProps &&
+                                props.pageProps.__N_REDIRECT
+                              )
+                            ) {
+                              _context.next = 62;
+                              break;
+                            }
+
+                            destination = props.pageProps.__N_REDIRECT; // check if destination is internal (resolves to a page) and attempt
+                            // client-navigation if it is falling back to hard navigation if
+                            // it's not
+
+                            if (!destination.startsWith("/")) {
+                              _context.next = 60;
+                              break;
+                            }
+
+                            parsedHref = (0,
+                            _parseRelativeUrl.parseRelativeUrl)(destination);
+
+                            this._resolveHref(parsedHref, pages);
+
+                            if (!pages.includes(parsedHref.pathname)) {
+                              _context.next = 60;
+                              break;
+                            }
+
+                            return _context.abrupt(
+                              "return",
+                              this.change(
+                                "replaceState",
+                                destination,
+                                destination,
+                                options
+                              )
+                            );
+
+                          case 60:
+                            window.location.href = destination;
+                            return _context.abrupt(
+                              "return",
+                              new Promise(function() {})
+                            );
+
+                          case 62:
                             Router.events.emit("beforeHistoryChange", as);
                             this.changeState(method, url, as, options);
 
                             if (false) {
                             }
 
-                            _context.next = 58;
+                            _context.next = 67;
                             return this.set(
                               route,
                               pathname,
@@ -1316,9 +1374,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               else throw e;
                             });
 
-                          case 58:
+                          case 67:
                             if (!error) {
-                              _context.next = 61;
+                              _context.next = 70;
                               break;
                             }
 
@@ -1329,28 +1387,28 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
                             throw error;
 
-                          case 61:
+                          case 70:
                             if (false) {
                             }
 
                             Router.events.emit("routeChangeComplete", as);
                             return _context.abrupt("return", true);
 
-                          case 66:
-                            _context.prev = 66;
+                          case 75:
+                            _context.prev = 75;
                             _context.t0 = _context["catch"](48);
 
                             if (!_context.t0.cancelled) {
-                              _context.next = 70;
+                              _context.next = 79;
                               break;
                             }
 
                             return _context.abrupt("return", false);
 
-                          case 70:
+                          case 79:
                             throw _context.t0;
 
-                          case 71:
+                          case 80:
                           case "end":
                             return _context.stop();
                         }
@@ -1358,7 +1416,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                     },
                     _callee,
                     this,
-                    [[48, 66]]
+                    [[48, 75]]
                   );
                 })
               );
Diff for index.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -118,13 +118,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.b1af6078fa6886051899.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8bbd9ad3a3297b42720e.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
Diff for link.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -123,13 +123,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.b1af6078fa6886051899.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8bbd9ad3a3297b42720e.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
Diff for withRouter.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -118,13 +118,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.b1af6078fa6886051899.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8bbd9ad3a3297b42720e.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       async=""
       crossorigin="anonymous"
       type="module"

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
buildDuration 15.6s 15.7s ⚠️ +107ms
nodeModulesSize 57.5 MB 57.5 MB ⚠️ +8.44 kB
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..f20b.js gzip 10.3 kB N/A N/A
framework.HASH.js gzip 39 kB 39 kB
main-ce79c9a..12c9.js gzip 7.36 kB 7.36 kB
webpack-e067..f178.js gzip 751 B 751 B
677f882d2ed8..df1d.js gzip N/A 10.4 kB N/A
Overall change 57.3 kB 57.5 kB ⚠️ +124 B
Client Bundles (main, webpack, commons) Modern Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..dule.js gzip 6.13 kB N/A N/A
framework.HA..dule.js gzip 39 kB 39 kB
main-9973c26..dule.js gzip 6.42 kB 6.42 kB
webpack-07c5..dule.js gzip 751 B 751 B
677f882d2ed8..dule.js gzip N/A 6.23 kB N/A
Overall change 52.3 kB 52.4 kB ⚠️ +103 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
polyfills-4b..e242.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-9a0b9e1..b37e.js gzip 1.28 kB 1.28 kB
_error-28298..e0c9.js gzip 3.44 kB 3.44 kB
hooks-89731c..c609.js gzip 887 B 887 B
index-17468f..5d83.js gzip 227 B 227 B
link-000f151..65d4.js gzip 1.29 kB 1.29 kB
routerDirect..924c.js gzip 284 B 284 B
withRouter-7..c13d.js gzip 284 B 284 B
Overall change 7.69 kB 7.69 kB
Client Pages Modern
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-75d3a82..dule.js gzip 625 B 625 B
_error-65c8a..dule.js gzip 2.29 kB 2.29 kB
hooks-cbf13f..dule.js gzip 387 B 387 B
index-b9a643..dule.js gzip 226 B 226 B
link-4cfda7a..dule.js gzip 1.26 kB 1.26 kB
routerDirect..dule.js gzip 284 B 284 B
withRouter-f..dule.js gzip 282 B 282 B
Overall change 5.35 kB 5.35 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_buildManifest.js gzip 322 B 322 B
_buildManife..dule.js gzip 330 B 330 B
Overall change 652 B 652 B
Serverless bundles Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_error.js 1.03 MB 1.03 MB ⚠️ +1.67 kB
404.html 4.22 kB 4.22 kB
hooks.html 3.86 kB 3.86 kB
index.js 1.03 MB 1.03 MB ⚠️ +1.67 kB
link.js 1.07 MB 1.08 MB ⚠️ +2.5 kB
routerDirect.js 1.07 MB 1.07 MB ⚠️ +2.5 kB
withRouter.js 1.07 MB 1.07 MB ⚠️ +2.5 kB
Overall change 5.28 MB 5.29 MB ⚠️ +10.9 kB
Commit: b815438

@ijjk ijjk marked this pull request as ready for review August 28, 2020 16:23
@ijjk ijjk requested a review from timneutkens August 31, 2020 15:15
@ijjk
Copy link
Member Author

ijjk commented Aug 31, 2020

Stats from current PR

Default Server Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
buildDuration 13.3s 13.8s ⚠️ +525ms
nodeModulesSize 57.4 MB 57.4 MB ⚠️ +8.61 kB
Page Load Tests Overall decrease ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
/ failed reqs 0 0
/ total time (seconds) 2.402 2.541 ⚠️ +0.14
/ avg req/sec 1040.99 983.94 ⚠️ -57.05
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.519 1.613 ⚠️ +0.09
/error-in-render avg req/sec 1645.38 1549.73 ⚠️ -95.65
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..f20b.js gzip 10.3 kB 10.4 kB ⚠️ +124 B
framework.HASH.js gzip 39 kB 39 kB
main-49b1fd5..c64c.js gzip 7.35 kB 7.35 kB
webpack-e067..f178.js gzip 751 B 751 B
Overall change 57.3 kB 57.5 kB ⚠️ +124 B
Client Bundles (main, webpack, commons) Modern Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..dule.js gzip 6.13 kB 6.23 kB ⚠️ +103 B
framework.HA..dule.js gzip 39 kB 39 kB
main-99715b4..dule.js gzip 6.4 kB 6.4 kB
webpack-07c5..dule.js gzip 751 B 751 B
Overall change 52.2 kB 52.3 kB ⚠️ +103 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
polyfills-4b..e242.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-9a0b9e1..b37e.js gzip 1.28 kB 1.28 kB
_error-28298..e0c9.js gzip 3.44 kB 3.44 kB
hooks-89731c..c609.js gzip 887 B 887 B
index-17468f..5d83.js gzip 227 B 227 B
link-000f151..65d4.js gzip 1.29 kB 1.29 kB
routerDirect..924c.js gzip 284 B 284 B
withRouter-7..c13d.js gzip 284 B 284 B
Overall change 7.69 kB 7.69 kB
Client Pages Modern
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-75d3a82..dule.js gzip 625 B 625 B
_error-65c8a..dule.js gzip 2.29 kB 2.29 kB
hooks-cbf13f..dule.js gzip 387 B 387 B
index-b9a643..dule.js gzip 226 B 226 B
link-4cfda7a..dule.js gzip 1.26 kB 1.26 kB
routerDirect..dule.js gzip 284 B 284 B
withRouter-f..dule.js gzip 282 B 282 B
Overall change 5.35 kB 5.35 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_buildManifest.js gzip 322 B 322 B
_buildManife..dule.js gzip 330 B 330 B
Overall change 652 B 652 B
Rendered Page Sizes Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
index.html gzip 971 B 971 B
link.html gzip 977 B 979 B ⚠️ +2 B
withRouter.html gzip 964 B 964 B
Overall change 2.91 kB 2.91 kB ⚠️ +2 B

Diffs

Diff for 677f882d2ed8..60.module.js
@@ -1041,7 +1041,39 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
               as,
               shallow
             );
-            var { error } = routeInfo;
+            var { error, props, __N_SSG, __N_SSP } = routeInfo; // handle redirect on client-transition
+
+            if (
+              (__N_SSG || __N_SSP) &&
+              props &&
+              props.pageProps &&
+              props.pageProps.__N_REDIRECT
+            ) {
+              var destination = props.pageProps.__N_REDIRECT; // check if destination is internal (resolves to a page) and attempt
+              // client-navigation if it is falling back to hard navigation if
+              // it's not
+
+              if (destination.startsWith("/")) {
+                var parsedHref = (0, _parseRelativeUrl.parseRelativeUrl)(
+                  destination
+                );
+
+                this._resolveHref(parsedHref, pages);
+
+                if (pages.includes(parsedHref.pathname)) {
+                  return this.change(
+                    "replaceState",
+                    destination,
+                    destination,
+                    options
+                  );
+                }
+              }
+
+              window.location.href = destination;
+              return new Promise(() => {});
+            }
+
             Router.events.emit("beforeHistoryChange", as);
             this.changeState(method, url, as, options);
Diff for 677f882d2ed8..886051899.js
@@ -1117,6 +1117,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                     missingParams,
                     routeInfo,
                     error,
+                    props,
+                    __N_SSG,
+                    __N_SSP,
+                    destination,
+                    parsedHref,
                     appComp;
 
                   return _regeneratorRuntime.wrap(
@@ -1297,14 +1302,67 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
 
                           case 51:
                             routeInfo = _context.sent;
-                            error = routeInfo.error;
+                            (error = routeInfo.error),
+                              (props = routeInfo.props),
+                              (__N_SSG = routeInfo.__N_SSG),
+                              (__N_SSP = routeInfo.__N_SSP); // handle redirect on client-transition
+
+                            if (
+                              !(
+                                (__N_SSG || __N_SSP) &&
+                                props &&
+                                props.pageProps &&
+                                props.pageProps.__N_REDIRECT
+                              )
+                            ) {
+                              _context.next = 62;
+                              break;
+                            }
+
+                            destination = props.pageProps.__N_REDIRECT; // check if destination is internal (resolves to a page) and attempt
+                            // client-navigation if it is falling back to hard navigation if
+                            // it's not
+
+                            if (!destination.startsWith("/")) {
+                              _context.next = 60;
+                              break;
+                            }
+
+                            parsedHref = (0,
+                            _parseRelativeUrl.parseRelativeUrl)(destination);
+
+                            this._resolveHref(parsedHref, pages);
+
+                            if (!pages.includes(parsedHref.pathname)) {
+                              _context.next = 60;
+                              break;
+                            }
+
+                            return _context.abrupt(
+                              "return",
+                              this.change(
+                                "replaceState",
+                                destination,
+                                destination,
+                                options
+                              )
+                            );
+
+                          case 60:
+                            window.location.href = destination;
+                            return _context.abrupt(
+                              "return",
+                              new Promise(function() {})
+                            );
+
+                          case 62:
                             Router.events.emit("beforeHistoryChange", as);
                             this.changeState(method, url, as, options);
 
                             if (false) {
                             }
 
-                            _context.next = 58;
+                            _context.next = 67;
                             return this.set(
                               route,
                               pathname,
@@ -1316,9 +1374,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               else throw e;
                             });
 
-                          case 58:
+                          case 67:
                             if (!error) {
-                              _context.next = 61;
+                              _context.next = 70;
                               break;
                             }
 
@@ -1329,28 +1387,28 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
                             throw error;
 
-                          case 61:
+                          case 70:
                             if (false) {
                             }
 
                             Router.events.emit("routeChangeComplete", as);
                             return _context.abrupt("return", true);
 
-                          case 66:
-                            _context.prev = 66;
+                          case 75:
+                            _context.prev = 75;
                             _context.t0 = _context["catch"](48);
 
                             if (!_context.t0.cancelled) {
-                              _context.next = 70;
+                              _context.next = 79;
                               break;
                             }
 
                             return _context.abrupt("return", false);
 
-                          case 70:
+                          case 79:
                             throw _context.t0;
 
-                          case 71:
+                          case 80:
                           case "end":
                             return _context.stop();
                         }
@@ -1358,7 +1416,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                     },
                     _callee,
                     this,
-                    [[48, 66]]
+                    [[48, 75]]
                   );
                 })
               );
Diff for index.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -118,13 +118,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.b1af6078fa6886051899.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8bbd9ad3a3297b42720e.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
Diff for link.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -123,13 +123,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.b1af6078fa6886051899.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8bbd9ad3a3297b42720e.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
Diff for withRouter.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -118,13 +118,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.b1af6078fa6886051899.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8bbd9ad3a3297b42720e.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       async=""
       crossorigin="anonymous"
       type="module"

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
buildDuration 14.9s 15.7s ⚠️ +737ms
nodeModulesSize 57.4 MB 57.4 MB ⚠️ +8.61 kB
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..f20b.js gzip 10.3 kB N/A N/A
framework.HASH.js gzip 39 kB 39 kB
main-49b1fd5..c64c.js gzip 7.35 kB 7.35 kB
webpack-e067..f178.js gzip 751 B 751 B
677f882d2ed8..df1d.js gzip N/A 10.4 kB N/A
Overall change 57.3 kB 57.5 kB ⚠️ +124 B
Client Bundles (main, webpack, commons) Modern Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..dule.js gzip 6.13 kB N/A N/A
framework.HA..dule.js gzip 39 kB 39 kB
main-99715b4..dule.js gzip 6.4 kB 6.4 kB
webpack-07c5..dule.js gzip 751 B 751 B
677f882d2ed8..dule.js gzip N/A 6.23 kB N/A
Overall change 52.2 kB 52.3 kB ⚠️ +103 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
polyfills-4b..e242.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-9a0b9e1..b37e.js gzip 1.28 kB 1.28 kB
_error-28298..e0c9.js gzip 3.44 kB 3.44 kB
hooks-89731c..c609.js gzip 887 B 887 B
index-17468f..5d83.js gzip 227 B 227 B
link-000f151..65d4.js gzip 1.29 kB 1.29 kB
routerDirect..924c.js gzip 284 B 284 B
withRouter-7..c13d.js gzip 284 B 284 B
Overall change 7.69 kB 7.69 kB
Client Pages Modern
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-75d3a82..dule.js gzip 625 B 625 B
_error-65c8a..dule.js gzip 2.29 kB 2.29 kB
hooks-cbf13f..dule.js gzip 387 B 387 B
index-b9a643..dule.js gzip 226 B 226 B
link-4cfda7a..dule.js gzip 1.26 kB 1.26 kB
routerDirect..dule.js gzip 284 B 284 B
withRouter-f..dule.js gzip 282 B 282 B
Overall change 5.35 kB 5.35 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_buildManifest.js gzip 322 B 322 B
_buildManife..dule.js gzip 330 B 330 B
Overall change 652 B 652 B
Serverless bundles Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_error.js 1.03 MB 1.03 MB ⚠️ +1.71 kB
404.html 4.22 kB 4.22 kB
hooks.html 3.86 kB 3.86 kB
index.js 1.03 MB 1.03 MB ⚠️ +1.71 kB
link.js 1.07 MB 1.08 MB ⚠️ +2.54 kB
routerDirect.js 1.07 MB 1.07 MB ⚠️ +2.54 kB
withRouter.js 1.07 MB 1.07 MB ⚠️ +2.54 kB
Overall change 5.28 MB 5.29 MB ⚠️ +11 kB
Commit: c2a4407

@ijjk
Copy link
Member Author

ijjk commented Sep 1, 2020

Stats from current PR

Default Server Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
buildDuration 13.5s 13.4s -88ms
nodeModulesSize 56.8 MB 56.8 MB ⚠️ +8.61 kB
Page Load Tests Overall increase ✓
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
/ failed reqs 0 0
/ total time (seconds) 2.511 2.517 ⚠️ +0.01
/ avg req/sec 995.46 993.27 ⚠️ -2.19
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.518 1.487 -0.03
/error-in-render avg req/sec 1646.58 1681.7 +35.12
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..f20b.js gzip 10.3 kB 10.4 kB ⚠️ +124 B
framework.HASH.js gzip 39 kB 39 kB
main-49b1fd5..c64c.js gzip 7.35 kB 7.35 kB
webpack-e067..f178.js gzip 751 B 751 B
Overall change 57.3 kB 57.5 kB ⚠️ +124 B
Client Bundles (main, webpack, commons) Modern Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..dule.js gzip 6.13 kB 6.23 kB ⚠️ +103 B
framework.HA..dule.js gzip 39 kB 39 kB
main-99715b4..dule.js gzip 6.4 kB 6.4 kB
webpack-07c5..dule.js gzip 751 B 751 B
Overall change 52.2 kB 52.3 kB ⚠️ +103 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
polyfills-4b..e242.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-9a0b9e1..b37e.js gzip 1.28 kB 1.28 kB
_error-28298..e0c9.js gzip 3.44 kB 3.44 kB
hooks-89731c..c609.js gzip 887 B 887 B
index-17468f..5d83.js gzip 227 B 227 B
link-000f151..65d4.js gzip 1.29 kB 1.29 kB
routerDirect..924c.js gzip 284 B 284 B
withRouter-7..c13d.js gzip 284 B 284 B
Overall change 7.69 kB 7.69 kB
Client Pages Modern
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-75d3a82..dule.js gzip 625 B 625 B
_error-65c8a..dule.js gzip 2.29 kB 2.29 kB
hooks-cbf13f..dule.js gzip 387 B 387 B
index-b9a643..dule.js gzip 226 B 226 B
link-4cfda7a..dule.js gzip 1.26 kB 1.26 kB
routerDirect..dule.js gzip 284 B 284 B
withRouter-f..dule.js gzip 282 B 282 B
Overall change 5.35 kB 5.35 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_buildManifest.js gzip 322 B 322 B
_buildManife..dule.js gzip 330 B 330 B
Overall change 652 B 652 B
Rendered Page Sizes Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
index.html gzip 971 B 971 B
link.html gzip 977 B 979 B ⚠️ +2 B
withRouter.html gzip 964 B 964 B
Overall change 2.91 kB 2.91 kB ⚠️ +2 B

Diffs

Diff for 677f882d2ed8..60.module.js
@@ -1041,7 +1041,39 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
               as,
               shallow
             );
-            var { error } = routeInfo;
+            var { error, props, __N_SSG, __N_SSP } = routeInfo; // handle redirect on client-transition
+
+            if (
+              (__N_SSG || __N_SSP) &&
+              props &&
+              props.pageProps &&
+              props.pageProps.__N_REDIRECT
+            ) {
+              var destination = props.pageProps.__N_REDIRECT; // check if destination is internal (resolves to a page) and attempt
+              // client-navigation if it is falling back to hard navigation if
+              // it's not
+
+              if (destination.startsWith("/")) {
+                var parsedHref = (0, _parseRelativeUrl.parseRelativeUrl)(
+                  destination
+                );
+
+                this._resolveHref(parsedHref, pages);
+
+                if (pages.includes(parsedHref.pathname)) {
+                  return this.change(
+                    "replaceState",
+                    destination,
+                    destination,
+                    options
+                  );
+                }
+              }
+
+              window.location.href = destination;
+              return new Promise(() => {});
+            }
+
             Router.events.emit("beforeHistoryChange", as);
             this.changeState(method, url, as, options);
Diff for 677f882d2ed8..886051899.js
@@ -1117,6 +1117,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                     missingParams,
                     routeInfo,
                     error,
+                    props,
+                    __N_SSG,
+                    __N_SSP,
+                    destination,
+                    parsedHref,
                     appComp;
 
                   return _regeneratorRuntime.wrap(
@@ -1297,14 +1302,67 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
 
                           case 51:
                             routeInfo = _context.sent;
-                            error = routeInfo.error;
+                            (error = routeInfo.error),
+                              (props = routeInfo.props),
+                              (__N_SSG = routeInfo.__N_SSG),
+                              (__N_SSP = routeInfo.__N_SSP); // handle redirect on client-transition
+
+                            if (
+                              !(
+                                (__N_SSG || __N_SSP) &&
+                                props &&
+                                props.pageProps &&
+                                props.pageProps.__N_REDIRECT
+                              )
+                            ) {
+                              _context.next = 62;
+                              break;
+                            }
+
+                            destination = props.pageProps.__N_REDIRECT; // check if destination is internal (resolves to a page) and attempt
+                            // client-navigation if it is falling back to hard navigation if
+                            // it's not
+
+                            if (!destination.startsWith("/")) {
+                              _context.next = 60;
+                              break;
+                            }
+
+                            parsedHref = (0,
+                            _parseRelativeUrl.parseRelativeUrl)(destination);
+
+                            this._resolveHref(parsedHref, pages);
+
+                            if (!pages.includes(parsedHref.pathname)) {
+                              _context.next = 60;
+                              break;
+                            }
+
+                            return _context.abrupt(
+                              "return",
+                              this.change(
+                                "replaceState",
+                                destination,
+                                destination,
+                                options
+                              )
+                            );
+
+                          case 60:
+                            window.location.href = destination;
+                            return _context.abrupt(
+                              "return",
+                              new Promise(function() {})
+                            );
+
+                          case 62:
                             Router.events.emit("beforeHistoryChange", as);
                             this.changeState(method, url, as, options);
 
                             if (false) {
                             }
 
-                            _context.next = 58;
+                            _context.next = 67;
                             return this.set(
                               route,
                               pathname,
@@ -1316,9 +1374,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               else throw e;
                             });
 
-                          case 58:
+                          case 67:
                             if (!error) {
-                              _context.next = 61;
+                              _context.next = 70;
                               break;
                             }
 
@@ -1329,28 +1387,28 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
                             throw error;
 
-                          case 61:
+                          case 70:
                             if (false) {
                             }
 
                             Router.events.emit("routeChangeComplete", as);
                             return _context.abrupt("return", true);
 
-                          case 66:
-                            _context.prev = 66;
+                          case 75:
+                            _context.prev = 75;
                             _context.t0 = _context["catch"](48);
 
                             if (!_context.t0.cancelled) {
-                              _context.next = 70;
+                              _context.next = 79;
                               break;
                             }
 
                             return _context.abrupt("return", false);
 
-                          case 70:
+                          case 79:
                             throw _context.t0;
 
-                          case 71:
+                          case 80:
                           case "end":
                             return _context.stop();
                         }
@@ -1358,7 +1416,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                     },
                     _callee,
                     this,
-                    [[48, 66]]
+                    [[48, 75]]
                   );
                 })
               );
Diff for index.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -118,13 +118,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.b1af6078fa6886051899.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8bbd9ad3a3297b42720e.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
Diff for link.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -123,13 +123,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.b1af6078fa6886051899.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8bbd9ad3a3297b42720e.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
Diff for withRouter.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -118,13 +118,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.b1af6078fa6886051899.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8bbd9ad3a3297b42720e.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.2206d208af7e83206260.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f413b69528f6d7b79516.module.js"
       async=""
       crossorigin="anonymous"
       type="module"

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
buildDuration 15.4s 15.4s -6ms
nodeModulesSize 56.8 MB 56.8 MB ⚠️ +8.61 kB
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..f20b.js gzip 10.3 kB N/A N/A
framework.HASH.js gzip 39 kB 39 kB
main-49b1fd5..c64c.js gzip 7.35 kB 7.35 kB
webpack-e067..f178.js gzip 751 B 751 B
677f882d2ed8..df1d.js gzip N/A 10.4 kB N/A
Overall change 57.3 kB 57.5 kB ⚠️ +124 B
Client Bundles (main, webpack, commons) Modern Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..dule.js gzip 6.13 kB N/A N/A
framework.HA..dule.js gzip 39 kB 39 kB
main-99715b4..dule.js gzip 6.4 kB 6.4 kB
webpack-07c5..dule.js gzip 751 B 751 B
677f882d2ed8..dule.js gzip N/A 6.23 kB N/A
Overall change 52.2 kB 52.3 kB ⚠️ +103 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
polyfills-4b..e242.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-9a0b9e1..b37e.js gzip 1.28 kB 1.28 kB
_error-28298..e0c9.js gzip 3.44 kB 3.44 kB
hooks-89731c..c609.js gzip 887 B 887 B
index-17468f..5d83.js gzip 227 B 227 B
link-000f151..65d4.js gzip 1.29 kB 1.29 kB
routerDirect..924c.js gzip 284 B 284 B
withRouter-7..c13d.js gzip 284 B 284 B
Overall change 7.69 kB 7.69 kB
Client Pages Modern
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-75d3a82..dule.js gzip 625 B 625 B
_error-65c8a..dule.js gzip 2.29 kB 2.29 kB
hooks-cbf13f..dule.js gzip 387 B 387 B
index-b9a643..dule.js gzip 226 B 226 B
link-4cfda7a..dule.js gzip 1.26 kB 1.26 kB
routerDirect..dule.js gzip 284 B 284 B
withRouter-f..dule.js gzip 282 B 282 B
Overall change 5.35 kB 5.35 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_buildManifest.js gzip 322 B 322 B
_buildManife..dule.js gzip 330 B 330 B
Overall change 652 B 652 B
Serverless bundles Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_error.js 1.03 MB 1.03 MB ⚠️ +1.71 kB
404.html 4.22 kB 4.22 kB
hooks.html 3.86 kB 3.86 kB
index.js 1.03 MB 1.03 MB ⚠️ +1.71 kB
link.js 1.07 MB 1.08 MB ⚠️ +2.54 kB
routerDirect.js 1.07 MB 1.07 MB ⚠️ +2.54 kB
withRouter.js 1.07 MB 1.07 MB ⚠️ +2.54 kB
Overall change 5.28 MB 5.29 MB ⚠️ +11 kB
Commit: e848e8d

@ijjk
Copy link
Member Author

ijjk commented Sep 1, 2020

Stats from current PR

Default Server Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
buildDuration 13.4s 13s -428ms
nodeModulesSize 55.9 MB 55.9 MB ⚠️ +8.61 kB
Page Load Tests Overall decrease ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
/ failed reqs 0 0
/ total time (seconds) 2.504 2.545 ⚠️ +0.04
/ avg req/sec 998.59 982.16 ⚠️ -16.43
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.504 1.57 ⚠️ +0.07
/error-in-render avg req/sec 1662.25 1592.34 ⚠️ -69.91
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..9ff9.js gzip 10.3 kB 10.4 kB ⚠️ +124 B
framework.HASH.js gzip 39 kB 39 kB
main-2db3d72..5955.js gzip 7.35 kB 7.35 kB
webpack-e067..f178.js gzip 751 B 751 B
Overall change 57.3 kB 57.5 kB ⚠️ +124 B
Client Bundles (main, webpack, commons) Modern Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..dule.js gzip 6.13 kB 6.23 kB ⚠️ +103 B
framework.HA..dule.js gzip 39 kB 39 kB
main-d7fe688..dule.js gzip 6.41 kB 6.41 kB
webpack-07c5..dule.js gzip 751 B 751 B
Overall change 52.3 kB 52.4 kB ⚠️ +103 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
polyfills-4b..e242.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-9a0b9e1..b37e.js gzip 1.28 kB 1.28 kB
_error-ed1b0..8fbd.js gzip 3.44 kB 3.44 kB
hooks-89731c..c609.js gzip 887 B 887 B
index-17468f..5d83.js gzip 227 B 227 B
link-ae98065..267e.js gzip 1.29 kB 1.29 kB
routerDirect..924c.js gzip 284 B 284 B
withRouter-7..c13d.js gzip 284 B 284 B
Overall change 7.69 kB 7.69 kB
Client Pages Modern
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-75d3a82..dule.js gzip 625 B 625 B
_error-4469a..dule.js gzip 2.29 kB 2.29 kB
hooks-cbf13f..dule.js gzip 387 B 387 B
index-b9a643..dule.js gzip 226 B 226 B
link-cb244c4..dule.js gzip 1.26 kB 1.26 kB
routerDirect..dule.js gzip 284 B 284 B
withRouter-f..dule.js gzip 282 B 282 B
Overall change 5.35 kB 5.35 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_buildManifest.js gzip 323 B 323 B
_buildManife..dule.js gzip 329 B 329 B
Overall change 652 B 652 B
Rendered Page Sizes Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
index.html gzip 971 B 972 B ⚠️ +1 B
link.html gzip 976 B 977 B ⚠️ +1 B
withRouter.html gzip 964 B 965 B ⚠️ +1 B
Overall change 2.91 kB 2.91 kB ⚠️ +3 B

Diffs

Diff for 677f882d2ed8..7000fca82.js
@@ -1117,6 +1117,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                     missingParams,
                     routeInfo,
                     error,
+                    props,
+                    __N_SSG,
+                    __N_SSP,
+                    destination,
+                    parsedHref,
                     appComp;
 
                   return _regeneratorRuntime.wrap(
@@ -1297,14 +1302,67 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
 
                           case 51:
                             routeInfo = _context.sent;
-                            error = routeInfo.error;
+                            (error = routeInfo.error),
+                              (props = routeInfo.props),
+                              (__N_SSG = routeInfo.__N_SSG),
+                              (__N_SSP = routeInfo.__N_SSP); // handle redirect on client-transition
+
+                            if (
+                              !(
+                                (__N_SSG || __N_SSP) &&
+                                props &&
+                                props.pageProps &&
+                                props.pageProps.__N_REDIRECT
+                              )
+                            ) {
+                              _context.next = 62;
+                              break;
+                            }
+
+                            destination = props.pageProps.__N_REDIRECT; // check if destination is internal (resolves to a page) and attempt
+                            // client-navigation if it is falling back to hard navigation if
+                            // it's not
+
+                            if (!destination.startsWith("/")) {
+                              _context.next = 60;
+                              break;
+                            }
+
+                            parsedHref = (0,
+                            _parseRelativeUrl.parseRelativeUrl)(destination);
+
+                            this._resolveHref(parsedHref, pages);
+
+                            if (!pages.includes(parsedHref.pathname)) {
+                              _context.next = 60;
+                              break;
+                            }
+
+                            return _context.abrupt(
+                              "return",
+                              this.change(
+                                "replaceState",
+                                destination,
+                                destination,
+                                options
+                              )
+                            );
+
+                          case 60:
+                            window.location.href = destination;
+                            return _context.abrupt(
+                              "return",
+                              new Promise(function() {})
+                            );
+
+                          case 62:
                             Router.events.emit("beforeHistoryChange", as);
                             this.changeState(method, url, as, options);
 
                             if (false) {
                             }
 
-                            _context.next = 58;
+                            _context.next = 67;
                             return this.set(
                               route,
                               pathname,
@@ -1316,9 +1374,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               else throw e;
                             });
 
-                          case 58:
+                          case 67:
                             if (!error) {
-                              _context.next = 61;
+                              _context.next = 70;
                               break;
                             }
 
@@ -1329,28 +1387,28 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
                             throw error;
 
-                          case 61:
+                          case 70:
                             if (false) {
                             }
 
                             Router.events.emit("routeChangeComplete", as);
                             return _context.abrupt("return", true);
 
-                          case 66:
-                            _context.prev = 66;
+                          case 75:
+                            _context.prev = 75;
                             _context.t0 = _context["catch"](48);
 
                             if (!_context.t0.cancelled) {
-                              _context.next = 70;
+                              _context.next = 79;
                               break;
                             }
 
                             return _context.abrupt("return", false);
 
-                          case 70:
+                          case 79:
                             throw _context.t0;
 
-                          case 71:
+                          case 80:
                           case "end":
                             return _context.stop();
                         }
@@ -1358,7 +1416,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                     },
                     _callee,
                     this,
-                    [[48, 66]]
+                    [[48, 75]]
                   );
                 })
               );
Diff for 677f882d2ed8..87.module.js
@@ -1041,7 +1041,39 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
               as,
               shallow
             );
-            var { error } = routeInfo;
+            var { error, props, __N_SSG, __N_SSP } = routeInfo; // handle redirect on client-transition
+
+            if (
+              (__N_SSG || __N_SSP) &&
+              props &&
+              props.pageProps &&
+              props.pageProps.__N_REDIRECT
+            ) {
+              var destination = props.pageProps.__N_REDIRECT; // check if destination is internal (resolves to a page) and attempt
+              // client-navigation if it is falling back to hard navigation if
+              // it's not
+
+              if (destination.startsWith("/")) {
+                var parsedHref = (0, _parseRelativeUrl.parseRelativeUrl)(
+                  destination
+                );
+
+                this._resolveHref(parsedHref, pages);
+
+                if (pages.includes(parsedHref.pathname)) {
+                  return this.change(
+                    "replaceState",
+                    destination,
+                    destination,
+                    options
+                  );
+                }
+              }
+
+              window.location.href = destination;
+              return new Promise(() => {});
+            }
+
             Router.events.emit("beforeHistoryChange", as);
             this.changeState(method, url, as, options);
Diff for index.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f48d291f6d1033f6c087.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.da7351d0ca3e06e03725.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -118,13 +118,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.abb28f9c6d97000fca82.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.b3b0a71d74c5ce213350.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f48d291f6d1033f6c087.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.da7351d0ca3e06e03725.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
Diff for link.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f48d291f6d1033f6c087.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.da7351d0ca3e06e03725.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -123,13 +123,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.abb28f9c6d97000fca82.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.b3b0a71d74c5ce213350.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f48d291f6d1033f6c087.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.da7351d0ca3e06e03725.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
Diff for withRouter.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f48d291f6d1033f6c087.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.da7351d0ca3e06e03725.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -118,13 +118,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.abb28f9c6d97000fca82.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.b3b0a71d74c5ce213350.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.f48d291f6d1033f6c087.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.da7351d0ca3e06e03725.module.js"
       async=""
       crossorigin="anonymous"
       type="module"

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
buildDuration 15.2s 15.4s ⚠️ +235ms
nodeModulesSize 55.9 MB 55.9 MB ⚠️ +8.61 kB
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..9ff9.js gzip 10.3 kB N/A N/A
framework.HASH.js gzip 39 kB 39 kB
main-2db3d72..5955.js gzip 7.35 kB 7.35 kB
webpack-e067..f178.js gzip 751 B 751 B
677f882d2ed8..2666.js gzip N/A 10.4 kB N/A
Overall change 57.3 kB 57.5 kB ⚠️ +124 B
Client Bundles (main, webpack, commons) Modern Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..dule.js gzip 6.13 kB N/A N/A
framework.HA..dule.js gzip 39 kB 39 kB
main-d7fe688..dule.js gzip 6.41 kB 6.41 kB
webpack-07c5..dule.js gzip 751 B 751 B
677f882d2ed8..dule.js gzip N/A 6.23 kB N/A
Overall change 52.3 kB 52.4 kB ⚠️ +103 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
polyfills-4b..e242.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-9a0b9e1..b37e.js gzip 1.28 kB 1.28 kB
_error-ed1b0..8fbd.js gzip 3.44 kB 3.44 kB
hooks-89731c..c609.js gzip 887 B 887 B
index-17468f..5d83.js gzip 227 B 227 B
link-ae98065..267e.js gzip 1.29 kB 1.29 kB
routerDirect..924c.js gzip 284 B 284 B
withRouter-7..c13d.js gzip 284 B 284 B
Overall change 7.69 kB 7.69 kB
Client Pages Modern
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-75d3a82..dule.js gzip 625 B 625 B
_error-4469a..dule.js gzip 2.29 kB 2.29 kB
hooks-cbf13f..dule.js gzip 387 B 387 B
index-b9a643..dule.js gzip 226 B 226 B
link-cb244c4..dule.js gzip 1.26 kB 1.26 kB
routerDirect..dule.js gzip 284 B 284 B
withRouter-f..dule.js gzip 282 B 282 B
Overall change 5.35 kB 5.35 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_buildManifest.js gzip 323 B 323 B
_buildManife..dule.js gzip 329 B 329 B
Overall change 652 B 652 B
Serverless bundles Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_error.js 1.03 MB 1.03 MB ⚠️ +1.71 kB
404.html 4.22 kB 4.22 kB
hooks.html 3.86 kB 3.86 kB
index.js 1.03 MB 1.03 MB ⚠️ +1.71 kB
link.js 1.07 MB 1.08 MB ⚠️ +2.54 kB
routerDirect.js 1.07 MB 1.07 MB ⚠️ +2.54 kB
withRouter.js 1.07 MB 1.07 MB ⚠️ +2.54 kB
Overall change 5.28 MB 5.29 MB ⚠️ +11 kB
Commit: 8fc4d0d

@@ -80,6 +85,7 @@ export type GetStaticPropsContext<Q extends ParsedUrlQuery = ParsedUrlQuery> = {

export type GetStaticPropsResult<P> = {
props: P
unstable_redirect?: Redirect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type is incorrect, you can either return unstable_redirect or props, not both

Copy link
Member

@timneutkens timneutkens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the comment

@ijjk
Copy link
Member Author

ijjk commented Sep 7, 2020

Stats from current PR

Default Server Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
buildDuration 12.4s 12.7s ⚠️ +288ms
nodeModulesSize 56.7 MB 56.7 MB ⚠️ +8.61 kB
Page Load Tests Overall increase ✓
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
/ failed reqs 0 0
/ total time (seconds) 2.247 2.206 -0.04
/ avg req/sec 1112.75 1133.36 +20.61
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.22 1.201 -0.02
/error-in-render avg req/sec 2048.9 2082.38 +33.48
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..7362.js gzip 10.6 kB 10.8 kB ⚠️ +124 B
framework.HASH.js gzip 39 kB 39 kB
main-979126c..02f7.js gzip 7.08 kB 7.08 kB
webpack-e067..f178.js gzip 751 B 751 B
Overall change 57.4 kB 57.6 kB ⚠️ +124 B
Client Bundles (main, webpack, commons) Modern Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..dule.js gzip 6.51 kB 6.62 kB ⚠️ +104 B
framework.HA..dule.js gzip 39 kB 39 kB
main-e37c8f7..dule.js gzip 6.14 kB 6.14 kB
webpack-07c5..dule.js gzip 751 B 751 B
Overall change 52.4 kB 52.5 kB ⚠️ +104 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
polyfills-4b..e242.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-9a0b9e1..b37e.js gzip 1.28 kB 1.28 kB
_error-ed1b0..8fbd.js gzip 3.44 kB 3.44 kB
hooks-89731c..c609.js gzip 887 B 887 B
index-17468f..5d83.js gzip 227 B 227 B
link-d2344ce..8b36.js gzip 1.3 kB 1.3 kB
routerDirect..924c.js gzip 284 B 284 B
withRouter-7..c13d.js gzip 284 B 284 B
Overall change 7.71 kB 7.71 kB
Client Pages Modern
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-75d3a82..dule.js gzip 625 B 625 B
_error-4469a..dule.js gzip 2.29 kB 2.29 kB
hooks-cbf13f..dule.js gzip 387 B 387 B
index-b9a643..dule.js gzip 226 B 226 B
link-f8c0daf..dule.js gzip 1.26 kB 1.26 kB
routerDirect..dule.js gzip 284 B 284 B
withRouter-f..dule.js gzip 282 B 282 B
Overall change 5.36 kB 5.36 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_buildManifest.js gzip 322 B 322 B
_buildManife..dule.js gzip 329 B 329 B
Overall change 651 B 651 B
Rendered Page Sizes Overall decrease ✓
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
index.html gzip 973 B 972 B -1 B
link.html gzip 979 B 979 B
withRouter.html gzip 966 B 965 B -1 B
Overall change 2.92 kB 2.92 kB -2 B

Diffs

Diff for 677f882d2ed8..2db076a1e.js
@@ -1214,6 +1214,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                     params,
                     routeInfo,
                     error,
+                    props,
+                    __N_SSG,
+                    __N_SSP,
+                    destination,
+                    parsedHref,
                     appComp;
 
                   return _regeneratorRuntime.wrap(
@@ -1406,14 +1411,67 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
 
                           case 51:
                             routeInfo = _context.sent;
-                            error = routeInfo.error;
+                            (error = routeInfo.error),
+                              (props = routeInfo.props),
+                              (__N_SSG = routeInfo.__N_SSG),
+                              (__N_SSP = routeInfo.__N_SSP); // handle redirect on client-transition
+
+                            if (
+                              !(
+                                (__N_SSG || __N_SSP) &&
+                                props &&
+                                props.pageProps &&
+                                props.pageProps.__N_REDIRECT
+                              )
+                            ) {
+                              _context.next = 62;
+                              break;
+                            }
+
+                            destination = props.pageProps.__N_REDIRECT; // check if destination is internal (resolves to a page) and attempt
+                            // client-navigation if it is falling back to hard navigation if
+                            // it's not
+
+                            if (!destination.startsWith("/")) {
+                              _context.next = 60;
+                              break;
+                            }
+
+                            parsedHref = (0,
+                            _parseRelativeUrl.parseRelativeUrl)(destination);
+
+                            this._resolveHref(parsedHref, pages);
+
+                            if (!pages.includes(parsedHref.pathname)) {
+                              _context.next = 60;
+                              break;
+                            }
+
+                            return _context.abrupt(
+                              "return",
+                              this.change(
+                                "replaceState",
+                                destination,
+                                destination,
+                                options
+                              )
+                            );
+
+                          case 60:
+                            window.location.href = destination;
+                            return _context.abrupt(
+                              "return",
+                              new Promise(function() {})
+                            );
+
+                          case 62:
                             Router.events.emit("beforeHistoryChange", as);
                             this.changeState(method, url, as, options);
 
                             if (false) {
                             }
 
-                            _context.next = 58;
+                            _context.next = 67;
                             return this.set(
                               route,
                               pathname,
@@ -1425,9 +1483,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               else throw e;
                             });
 
-                          case 58:
+                          case 67:
                             if (!error) {
-                              _context.next = 61;
+                              _context.next = 70;
                               break;
                             }
 
@@ -1438,28 +1496,28 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
                             throw error;
 
-                          case 61:
+                          case 70:
                             if (false) {
                             }
 
                             Router.events.emit("routeChangeComplete", as);
                             return _context.abrupt("return", true);
 
-                          case 66:
-                            _context.prev = 66;
+                          case 75:
+                            _context.prev = 75;
                             _context.t0 = _context["catch"](48);
 
                             if (!_context.t0.cancelled) {
-                              _context.next = 70;
+                              _context.next = 79;
                               break;
                             }
 
                             return _context.abrupt("return", false);
 
-                          case 70:
+                          case 79:
                             throw _context.t0;
 
-                          case 71:
+                          case 80:
                           case "end":
                             return _context.stop();
                         }
@@ -1467,7 +1525,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                     },
                     _callee,
                     this,
-                    [[48, 66]]
+                    [[48, 75]]
                   );
                 })
               );
Diff for 677f882d2ed8..7e.module.js
@@ -1136,7 +1136,39 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
               as,
               shallow
             );
-            var { error } = routeInfo;
+            var { error, props, __N_SSG, __N_SSP } = routeInfo; // handle redirect on client-transition
+
+            if (
+              (__N_SSG || __N_SSP) &&
+              props &&
+              props.pageProps &&
+              props.pageProps.__N_REDIRECT
+            ) {
+              var destination = props.pageProps.__N_REDIRECT; // check if destination is internal (resolves to a page) and attempt
+              // client-navigation if it is falling back to hard navigation if
+              // it's not
+
+              if (destination.startsWith("/")) {
+                var parsedHref = (0, _parseRelativeUrl.parseRelativeUrl)(
+                  destination
+                );
+
+                this._resolveHref(parsedHref, pages);
+
+                if (pages.includes(parsedHref.pathname)) {
+                  return this.change(
+                    "replaceState",
+                    destination,
+                    destination,
+                    options
+                  );
+                }
+              }
+
+              window.location.href = destination;
+              return new Promise(() => {});
+            }
+
             Router.events.emit("beforeHistoryChange", as);
             this.changeState(method, url, as, options);
Diff for index.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.e1be7d91975a4e7aea7e.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.7d132ab979d135defe45.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -118,13 +118,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.48509355e812db076a1e.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.3708ec5b82fc3c4f674d.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.e1be7d91975a4e7aea7e.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.7d132ab979d135defe45.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
Diff for link.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.e1be7d91975a4e7aea7e.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.7d132ab979d135defe45.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -123,13 +123,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.48509355e812db076a1e.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.3708ec5b82fc3c4f674d.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.e1be7d91975a4e7aea7e.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.7d132ab979d135defe45.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
Diff for withRouter.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.e1be7d91975a4e7aea7e.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.7d132ab979d135defe45.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -118,13 +118,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.48509355e812db076a1e.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.3708ec5b82fc3c4f674d.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.e1be7d91975a4e7aea7e.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.7d132ab979d135defe45.module.js"
       async=""
       crossorigin="anonymous"
       type="module"

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
buildDuration 14.4s 14s -410ms
nodeModulesSize 56.7 MB 56.7 MB ⚠️ +8.61 kB
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..7362.js gzip 10.6 kB N/A N/A
framework.HASH.js gzip 39 kB 39 kB
main-979126c..02f7.js gzip 7.08 kB 7.08 kB
webpack-e067..f178.js gzip 751 B 751 B
677f882d2ed8..a2cc.js gzip N/A 10.8 kB N/A
Overall change 57.4 kB 57.6 kB ⚠️ +124 B
Client Bundles (main, webpack, commons) Modern Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..dule.js gzip 6.51 kB N/A N/A
framework.HA..dule.js gzip 39 kB 39 kB
main-e37c8f7..dule.js gzip 6.14 kB 6.14 kB
webpack-07c5..dule.js gzip 751 B 751 B
677f882d2ed8..dule.js gzip N/A 6.62 kB N/A
Overall change 52.4 kB 52.5 kB ⚠️ +104 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
polyfills-4b..e242.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-9a0b9e1..b37e.js gzip 1.28 kB 1.28 kB
_error-ed1b0..8fbd.js gzip 3.44 kB 3.44 kB
hooks-89731c..c609.js gzip 887 B 887 B
index-17468f..5d83.js gzip 227 B 227 B
link-d2344ce..8b36.js gzip 1.3 kB 1.3 kB
routerDirect..924c.js gzip 284 B 284 B
withRouter-7..c13d.js gzip 284 B 284 B
Overall change 7.71 kB 7.71 kB
Client Pages Modern
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-75d3a82..dule.js gzip 625 B 625 B
_error-4469a..dule.js gzip 2.29 kB 2.29 kB
hooks-cbf13f..dule.js gzip 387 B 387 B
index-b9a643..dule.js gzip 226 B 226 B
link-f8c0daf..dule.js gzip 1.26 kB 1.26 kB
routerDirect..dule.js gzip 284 B 284 B
withRouter-f..dule.js gzip 282 B 282 B
Overall change 5.36 kB 5.36 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_buildManifest.js gzip 322 B 322 B
_buildManife..dule.js gzip 329 B 329 B
Overall change 651 B 651 B
Serverless bundles Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_error.js 1.03 MB 1.03 MB ⚠️ +1.71 kB
404.html 4.22 kB 4.22 kB
hooks.html 3.86 kB 3.86 kB
index.js 1.03 MB 1.03 MB ⚠️ +1.71 kB
link.js 1.08 MB 1.08 MB ⚠️ +2.54 kB
routerDirect.js 1.07 MB 1.07 MB ⚠️ +2.54 kB
withRouter.js 1.07 MB 1.07 MB ⚠️ +2.54 kB
Overall change 5.29 MB 5.3 MB ⚠️ +11 kB
Commit: 461c52a

@ijjk
Copy link
Member Author

ijjk commented Sep 7, 2020

Failing test suites

Commit: 461c52a

test/integration/build-output/test/index.test.js

  • Build Output > Basic Application Output > should not deviate from snapshot
Expand output

● Build Output › Basic Application Output › should not deviate from snapshot

expect(received).toBeLessThanOrEqual(expected)

Expected: <= 0
Received:    0.10000000000000142

   96 | 
   97 |       // should be no bigger than 60.2 kb
>  98 |       expect(parseFloat(indexFirstLoad) - 60.3).toBeLessThanOrEqual(0)
      |                                                 ^
   99 |       expect(indexFirstLoad.endsWith('kB')).toBe(true)
  100 | 
  101 |       expect(parseFloat(err404Size) - 3.5).toBeLessThanOrEqual(0)

  at Object.<anonymous> (integration/build-output/test/index.test.js:98:49)

test/integration/size-limit/test/index.test.js

  • Production response size > should not increase the overall response size of default build
Expand output

● Production response size › should not increase the overall response size of default build

expect(received).toBeLessThanOrEqual(expected)

Expected: <= 1024
Received:    1122

  82 |     // These numbers are without gzip compression!
  83 |     const delta = responseSizesBytes - 278 * 1024
> 84 |     expect(delta).toBeLessThanOrEqual(1024) // don't increase size more than 1kb
     |                   ^
  85 |     expect(delta).toBeGreaterThanOrEqual(-1024) // don't decrease size more than 1kb without updating target
  86 |   })
  87 | 

  at Object.<anonymous> (integration/size-limit/test/index.test.js:84:19)

@ijjk
Copy link
Member Author

ijjk commented Sep 7, 2020

Stats from current PR

Default Server Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
buildDuration 11.7s 11.8s ⚠️ +110ms
nodeModulesSize 56.7 MB 56.7 MB ⚠️ +8.61 kB
Page Load Tests Overall decrease ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
/ failed reqs 0 0
/ total time (seconds) 2.061 2.093 ⚠️ +0.03
/ avg req/sec 1212.89 1194.17 ⚠️ -18.72
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.1 1.14 ⚠️ +0.04
/error-in-render avg req/sec 2272.11 2193.51 ⚠️ -78.6
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..7362.js gzip 10.6 kB 10.8 kB ⚠️ +124 B
framework.HASH.js gzip 39 kB 39 kB
main-979126c..02f7.js gzip 7.08 kB 7.08 kB
webpack-e067..f178.js gzip 751 B 751 B
Overall change 57.4 kB 57.6 kB ⚠️ +124 B
Client Bundles (main, webpack, commons) Modern Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..dule.js gzip 6.51 kB 6.62 kB ⚠️ +104 B
framework.HA..dule.js gzip 39 kB 39 kB
main-e37c8f7..dule.js gzip 6.14 kB 6.14 kB
webpack-07c5..dule.js gzip 751 B 751 B
Overall change 52.4 kB 52.5 kB ⚠️ +104 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
polyfills-4b..e242.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-9a0b9e1..b37e.js gzip 1.28 kB 1.28 kB
_error-ed1b0..8fbd.js gzip 3.44 kB 3.44 kB
hooks-89731c..c609.js gzip 887 B 887 B
index-17468f..5d83.js gzip 227 B 227 B
link-d2344ce..8b36.js gzip 1.3 kB 1.3 kB
routerDirect..924c.js gzip 284 B 284 B
withRouter-7..c13d.js gzip 284 B 284 B
Overall change 7.71 kB 7.71 kB
Client Pages Modern
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-75d3a82..dule.js gzip 625 B 625 B
_error-4469a..dule.js gzip 2.29 kB 2.29 kB
hooks-cbf13f..dule.js gzip 387 B 387 B
index-b9a643..dule.js gzip 226 B 226 B
link-f8c0daf..dule.js gzip 1.26 kB 1.26 kB
routerDirect..dule.js gzip 284 B 284 B
withRouter-f..dule.js gzip 282 B 282 B
Overall change 5.36 kB 5.36 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_buildManifest.js gzip 322 B 322 B
_buildManife..dule.js gzip 329 B 329 B
Overall change 651 B 651 B
Rendered Page Sizes Overall decrease ✓
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
index.html gzip 973 B 972 B -1 B
link.html gzip 979 B 979 B
withRouter.html gzip 966 B 965 B -1 B
Overall change 2.92 kB 2.92 kB -2 B

Diffs

Diff for 677f882d2ed8..2db076a1e.js
@@ -1214,6 +1214,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                     params,
                     routeInfo,
                     error,
+                    props,
+                    __N_SSG,
+                    __N_SSP,
+                    destination,
+                    parsedHref,
                     appComp;
 
                   return _regeneratorRuntime.wrap(
@@ -1406,14 +1411,67 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
 
                           case 51:
                             routeInfo = _context.sent;
-                            error = routeInfo.error;
+                            (error = routeInfo.error),
+                              (props = routeInfo.props),
+                              (__N_SSG = routeInfo.__N_SSG),
+                              (__N_SSP = routeInfo.__N_SSP); // handle redirect on client-transition
+
+                            if (
+                              !(
+                                (__N_SSG || __N_SSP) &&
+                                props &&
+                                props.pageProps &&
+                                props.pageProps.__N_REDIRECT
+                              )
+                            ) {
+                              _context.next = 62;
+                              break;
+                            }
+
+                            destination = props.pageProps.__N_REDIRECT; // check if destination is internal (resolves to a page) and attempt
+                            // client-navigation if it is falling back to hard navigation if
+                            // it's not
+
+                            if (!destination.startsWith("/")) {
+                              _context.next = 60;
+                              break;
+                            }
+
+                            parsedHref = (0,
+                            _parseRelativeUrl.parseRelativeUrl)(destination);
+
+                            this._resolveHref(parsedHref, pages);
+
+                            if (!pages.includes(parsedHref.pathname)) {
+                              _context.next = 60;
+                              break;
+                            }
+
+                            return _context.abrupt(
+                              "return",
+                              this.change(
+                                "replaceState",
+                                destination,
+                                destination,
+                                options
+                              )
+                            );
+
+                          case 60:
+                            window.location.href = destination;
+                            return _context.abrupt(
+                              "return",
+                              new Promise(function() {})
+                            );
+
+                          case 62:
                             Router.events.emit("beforeHistoryChange", as);
                             this.changeState(method, url, as, options);
 
                             if (false) {
                             }
 
-                            _context.next = 58;
+                            _context.next = 67;
                             return this.set(
                               route,
                               pathname,
@@ -1425,9 +1483,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               else throw e;
                             });
 
-                          case 58:
+                          case 67:
                             if (!error) {
-                              _context.next = 61;
+                              _context.next = 70;
                               break;
                             }
 
@@ -1438,28 +1496,28 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
                             throw error;
 
-                          case 61:
+                          case 70:
                             if (false) {
                             }
 
                             Router.events.emit("routeChangeComplete", as);
                             return _context.abrupt("return", true);
 
-                          case 66:
-                            _context.prev = 66;
+                          case 75:
+                            _context.prev = 75;
                             _context.t0 = _context["catch"](48);
 
                             if (!_context.t0.cancelled) {
-                              _context.next = 70;
+                              _context.next = 79;
                               break;
                             }
 
                             return _context.abrupt("return", false);
 
-                          case 70:
+                          case 79:
                             throw _context.t0;
 
-                          case 71:
+                          case 80:
                           case "end":
                             return _context.stop();
                         }
@@ -1467,7 +1525,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                     },
                     _callee,
                     this,
-                    [[48, 66]]
+                    [[48, 75]]
                   );
                 })
               );
Diff for 677f882d2ed8..7e.module.js
@@ -1136,7 +1136,39 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
               as,
               shallow
             );
-            var { error } = routeInfo;
+            var { error, props, __N_SSG, __N_SSP } = routeInfo; // handle redirect on client-transition
+
+            if (
+              (__N_SSG || __N_SSP) &&
+              props &&
+              props.pageProps &&
+              props.pageProps.__N_REDIRECT
+            ) {
+              var destination = props.pageProps.__N_REDIRECT; // check if destination is internal (resolves to a page) and attempt
+              // client-navigation if it is falling back to hard navigation if
+              // it's not
+
+              if (destination.startsWith("/")) {
+                var parsedHref = (0, _parseRelativeUrl.parseRelativeUrl)(
+                  destination
+                );
+
+                this._resolveHref(parsedHref, pages);
+
+                if (pages.includes(parsedHref.pathname)) {
+                  return this.change(
+                    "replaceState",
+                    destination,
+                    destination,
+                    options
+                  );
+                }
+              }
+
+              window.location.href = destination;
+              return new Promise(() => {});
+            }
+
             Router.events.emit("beforeHistoryChange", as);
             this.changeState(method, url, as, options);
Diff for index.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.e1be7d91975a4e7aea7e.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.7d132ab979d135defe45.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -118,13 +118,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.48509355e812db076a1e.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.3708ec5b82fc3c4f674d.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.e1be7d91975a4e7aea7e.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.7d132ab979d135defe45.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
Diff for link.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.e1be7d91975a4e7aea7e.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.7d132ab979d135defe45.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -123,13 +123,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.48509355e812db076a1e.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.3708ec5b82fc3c4f674d.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.e1be7d91975a4e7aea7e.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.7d132ab979d135defe45.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
Diff for withRouter.html
@@ -25,7 +25,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.e1be7d91975a4e7aea7e.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.7d132ab979d135defe45.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -118,13 +118,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.48509355e812db076a1e.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.3708ec5b82fc3c4f674d.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.e1be7d91975a4e7aea7e.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.7d132ab979d135defe45.module.js"
       async=""
       crossorigin="anonymous"
       type="module"

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
buildDuration 13.7s 13.3s -317ms
nodeModulesSize 56.7 MB 56.7 MB ⚠️ +8.61 kB
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..7362.js gzip 10.6 kB N/A N/A
framework.HASH.js gzip 39 kB 39 kB
main-979126c..02f7.js gzip 7.08 kB 7.08 kB
webpack-e067..f178.js gzip 751 B 751 B
677f882d2ed8..a2cc.js gzip N/A 10.8 kB N/A
Overall change 57.4 kB 57.6 kB ⚠️ +124 B
Client Bundles (main, webpack, commons) Modern Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
677f882d2ed8..dule.js gzip 6.51 kB N/A N/A
framework.HA..dule.js gzip 39 kB 39 kB
main-e37c8f7..dule.js gzip 6.14 kB 6.14 kB
webpack-07c5..dule.js gzip 751 B 751 B
677f882d2ed8..dule.js gzip N/A 6.62 kB N/A
Overall change 52.4 kB 52.5 kB ⚠️ +104 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
polyfills-4b..e242.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-9a0b9e1..b37e.js gzip 1.28 kB 1.28 kB
_error-ed1b0..8fbd.js gzip 3.44 kB 3.44 kB
hooks-89731c..c609.js gzip 887 B 887 B
index-17468f..5d83.js gzip 227 B 227 B
link-d2344ce..8b36.js gzip 1.3 kB 1.3 kB
routerDirect..924c.js gzip 284 B 284 B
withRouter-7..c13d.js gzip 284 B 284 B
Overall change 7.71 kB 7.71 kB
Client Pages Modern
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_app-75d3a82..dule.js gzip 625 B 625 B
_error-4469a..dule.js gzip 2.29 kB 2.29 kB
hooks-cbf13f..dule.js gzip 387 B 387 B
index-b9a643..dule.js gzip 226 B 226 B
link-f8c0daf..dule.js gzip 1.26 kB 1.26 kB
routerDirect..dule.js gzip 284 B 284 B
withRouter-f..dule.js gzip 282 B 282 B
Overall change 5.36 kB 5.36 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_buildManifest.js gzip 322 B 322 B
_buildManife..dule.js gzip 329 B 329 B
Overall change 651 B 651 B
Serverless bundles Overall increase ⚠️
vercel/next.js canary ijjk/next.js add/gssp-redirect-handling Change
_error.js 1.03 MB 1.03 MB ⚠️ +1.71 kB
404.html 4.22 kB 4.22 kB
hooks.html 3.86 kB 3.86 kB
index.js 1.03 MB 1.03 MB ⚠️ +1.71 kB
link.js 1.08 MB 1.08 MB ⚠️ +2.54 kB
routerDirect.js 1.07 MB 1.07 MB ⚠️ +2.54 kB
withRouter.js 1.07 MB 1.07 MB ⚠️ +2.54 kB
Overall change 5.29 MB 5.3 MB ⚠️ +11 kB
Commit: e3bb846

@timneutkens timneutkens merged commit bc80fb4 into vercel:canary Sep 8, 2020
@DmitryKvant
Copy link

DmitryKvant commented Sep 19, 2020

Can I use it for redirect with status 404 in getStaticProps/SSG?

return { unstable_redirect: { permanent: true, destination: '/404' } }

HitoriSensei pushed a commit to HitoriSensei/next.js that referenced this pull request Sep 26, 2020
@devknoll devknoll mentioned this pull request Oct 19, 2020
@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Returning redirects from getServerSideProps / getStaticProps
3 participants